home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / MPW Related / Universal Interfaces / RIncludes / MixedMode.r < prev    next >
Encoding:
Text File  |  1993-12-13  |  7.5 KB  |  278 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MixedMode.r
  3.  
  4.     Contains:    Rez templates for creating resource based Mixed Mode stuff
  5.  
  6. */
  7.  
  8.  
  9.  
  10. #define    GoMixedModeTrapType    unsigned hex integer
  11. #define    VersionType byte
  12. #define    SelectorsAreIndexableType boolean
  13. #define    Reserved1Type fill long
  14. #define    Reserved2Type fill byte
  15. #define    SelectorInfoType hex byte
  16. #define    RoutineCountType integer
  17.  
  18. #define ProcInfoType binary longint
  19. #define    Reserved3Type fill byte
  20. #define    ISAType byte
  21. #define ProcDescriptorIsRelativeType boolean
  22. #define    FragmentNeedsPreparingType boolean
  23. #define    UseNativeISAType boolean
  24. #define    DontPassSelectorType boolean
  25. #define    RoutineIsDispatchedDefaultType boolean
  26. #define    ProcDescriptorType longint
  27. #define    Reserved4Type fill long
  28. #define    SelectorType longint
  29.  
  30. #define    _MixedModeMagic 0xAAFE
  31. #define    kRoutineDescriptorVersion 7
  32.  
  33. #define    kM68kISA 0
  34. #define    kPowerPCISA 1
  35.  
  36. /*
  37.     Use the 'rdes' template to define a “native resource” which 
  38.     starts with a routine descriptor. Such resources contain 
  39.     just PowerPC code. 
  40.     
  41.     Note that such resources can only be executed on PowerPC
  42.     machines. Executing them on a 68K machine will result 
  43.     in a crash.
  44.  
  45.     To create a “native resource”, use something like the following:
  46.     
  47. #include "MixedMode.r"
  48.  
  49. type 'BDef' as 'rdes';
  50.  
  51. resource 'BDef' (1) {
  52.     $1,                                        // ProcInfo
  53.     $$Resource("BDef.rsrc", 'pCod', 128)    // Specify name, type, and ID of resource
  54.                                             //   containing a pef container
  55. };
  56.  
  57. */
  58.  
  59. type 'rdes' { 
  60. Top:
  61.     /* Routine Descriptor */
  62.     GoMixedModeTrapType             = _MixedModeMagic;
  63.     VersionType                        = kRoutineDescriptorVersion;
  64.     fill bit [7];
  65.     SelectorsAreIndexableType        = FALSE;
  66.     Reserved1Type;
  67.     Reserved2Type;
  68.     SelectorInfoType                = 0;
  69.     RoutineCountType                = 0;
  70.  
  71.     /* Routine Record */
  72.     ProcInfoType;
  73.     Reserved3Type;
  74.     ISAType                            = kPowerPCISA;
  75.     fill bit [11];
  76.     RoutineIsDispatchedDefaultType     = FALSE;
  77.     DontPassSelectorType            = FALSE;
  78.     UseNativeISAType                = TRUE;
  79.     FragmentNeedsPreparingType        = TRUE;
  80.     ProcDescriptorIsRelativeType    = TRUE;
  81.     ProcDescriptorType                = (BeginningOfPowerPCCode-Top) / 8;
  82.     Reserved4Type;
  83.     SelectorType                    = 0;
  84.     Align LONG;
  85.  
  86. BeginningOfPowerPCCode:
  87.     hex string;                        // The PEF container starts here
  88. };
  89.  
  90.  
  91. /*
  92.     Use the 'fdes' template to define a “fat resource” which 
  93.     starts with a routine descriptor and contains both 68K and 
  94.     PowerPC code. 
  95.     
  96.     Note that such resources can only be executed on a machine
  97.     with MixedMode installed. To create “safe fat resources”
  98.     which will run on all machines, use the 'sdes' template
  99.     defined below.
  100.  
  101.     To create a “fat resource”, use something like the following:
  102.     
  103. #include "MixedMode.r"
  104.  
  105. type 'BDef' as 'fdes';
  106.  
  107. resource 'BDef' (1) {
  108.     $1,                                        // 68K ProcInfo
  109.     $1,                                        // PowerPC ProcInfo
  110.     $$Resource("BDef.rsrc", 'oCod', 128),    // Specify name, type, and ID of resource
  111.                                             //   containing 68k code
  112.     $$Resource("BDef.rsrc", 'pCod', 128)    // Specify name, type, and ID of resource
  113.                                             //   containing a pef container
  114. };
  115.  
  116. */
  117.  
  118. /*  Fat Routines  */
  119. type 'fdes' { 
  120. Top:
  121.     /* Routine Descriptor */
  122.     GoMixedModeTrapType             = _MixedModeMagic;
  123.     VersionType                        = kRoutineDescriptorVersion;
  124.     fill bit [7];
  125.     SelectorsAreIndexableType        = FALSE;
  126.     Reserved1Type;
  127.     Reserved2Type;
  128.     SelectorInfoType                = 0;
  129.     RoutineCountType                = 1;
  130.  
  131.     /* 68k Routine Record */
  132.     ProcInfoType;
  133.     Reserved3Type;
  134.     ISAType                            = kM68kISA;
  135.     fill bit [11];
  136.     RoutineIsDispatchedDefaultType     = FALSE;
  137.     DontPassSelectorType            = FALSE;
  138.     UseNativeISAType                = TRUE;
  139.     FragmentNeedsPreparingType        = FALSE;
  140.     ProcDescriptorIsRelativeType    = TRUE;
  141.     ProcDescriptorType                = (BeginningOf68KCode-Top) / 8;
  142.     Reserved4Type;
  143.     SelectorType                    = 0;
  144.  
  145.     /* PowerPC Routine Record 1 */
  146.     ProcInfoType;
  147.     Reserved3Type;
  148.     ISAType                            = kPowerPCISA;
  149.     fill bit [11];
  150.     RoutineIsDispatchedDefaultType     = FALSE;
  151.     DontPassSelectorType            = FALSE;
  152.     UseNativeISAType                = TRUE;
  153.     FragmentNeedsPreparingType        = TRUE;
  154.     ProcDescriptorIsRelativeType    = TRUE;
  155.     ProcDescriptorType                = (BeginningOfPowerPCCode-Top) / 8;
  156.     Reserved4Type;
  157.     SelectorType                    = 0;
  158.     Align LONG;
  159.  
  160. BeginningOf68kCode:
  161.     hex string;                // The code starts here
  162.     
  163.     Align LONG;
  164.  
  165. BeginningOfPowerPCCode:
  166.     hex string;                // The PEF container starts here
  167. };
  168.  
  169.  
  170. /*
  171.     Use the 'sdes' template to define a “safe fat resource” which 
  172.     contains both 68K and PowerPC code. A safe fat resource starts
  173.     with 68K code which is executed the first time the resource
  174.     is called. This code determines if MixedMode is present. If
  175.     so, a routine descriptor is moved to the beginning of the
  176.     resource. If not, a branch instruction to the 68K portion
  177.     of the code is placed at the beginning of the resource. 
  178.     Therefore, the first time the resource is executed, there 
  179.     is some overhead incurred. However, subsequent calls 
  180.     will be fast.
  181.     
  182.     Note: This template cannot currently be used for resources
  183.     containing code with register-based calling conventions
  184.     because the 68K code at the beginning of the resource
  185.     uses D0, A0, and A1.
  186.     
  187.     To create a “safe fat resource”, use something like the following:
  188.     
  189. #include "MixedMode.r"
  190.  
  191. type 'BDef' as 'sdes';
  192.  
  193. resource 'BDef' (1) {
  194.     $1,                                        // 68K ProcInfo
  195.     $1,                                        // PowerPC ProcInfo
  196.     $$Resource("BDef.rsrc", 'oCod', 128),    // Specify name, type, and ID of resource
  197.                                             //   containing 68k code
  198.     $$Resource("BDef.rsrc", 'pCod', 128)    // Specify name, type, and ID of resource
  199.                                             //   containing a pef container
  200. };
  201.  
  202. */
  203.  
  204. /*  Safe Fat Resources  */
  205. type 'sdes' { 
  206. Top:
  207.     hex string    = 
  208.         $"303C A89F"    //     SafeFatRsrc        MOVE.W        #_Unimplemented, D0
  209.         $"A746"            //                     _GetToolBoxTrapAddress
  210.         $"2F08"            //                     MOVE.L        A0, -(SP)
  211.         $"303C AAFE"    //                     MOVE.W        #_MixedModeMagic, D0 
  212.         $"A746"            //                     _GetToolBoxTrapAddress
  213.         $"B1DF"            //                     CMPA.L        (SP)+, A0                // Is MM installed?
  214.         $"661A"            //                     BNE.S        InstallPPCCode
  215.         $"41FA FFEC"    // Install68KCode    LEA            SafeFatRsrc, A0
  216.         $"30FC 6000"    //                    MOVE.W        #$6000, (A0)+            // Generate a BRA instruction
  217.         $"43FA 001E"    //                    LEA            FatRD, A1
  218.         $"2029 0014"    //                    MOVE.L        20(A1), D0                // Get 68K code offset
  219.         $"5580"            //                    SUBQ.L        #2, D0
  220.         $"3080"            //                    MOVE.W        D0, (A0)                // Fill in the second word of the BRA
  221.         $"7001 A198"    //                    _FlushInstructionCache
  222.         $"60D4"            //                    BRA.S        SafeFatRsrc
  223.         $"43FA FFD2"    // InstallPPCCode    LEA            SafeFatRsrc, A1
  224.         $"41FA 0008"    //                    LEA            FatRD, A0
  225.         $"7034"            //                    MOVE.L        #52, D0
  226.         $"A02E"            //                    _BlockMove                            // Move R.D. to top of rsrc
  227.         $"60C6";        //                     BRA            SafeFatRsrc
  228.                         // FatRD            // The fat routine descriptor follows
  229.  
  230.     /* Routine Descriptor */
  231.     GoMixedModeTrapType             = _MixedModeMagic;
  232.     VersionType                        = kRoutineDescriptorVersion;
  233.     fill bit [7];
  234.     SelectorsAreIndexableType        = FALSE;
  235.     Reserved1Type;
  236.     Reserved2Type;
  237.     SelectorInfoType                = 0;
  238.     RoutineCountType                = 1;
  239.  
  240.     /* Routine Record */
  241.     ProcInfoType;
  242.     Reserved3Type;
  243.     ISAType                            = kM68kISA;
  244.     fill bit [11];
  245.     RoutineIsDispatchedDefaultType     = FALSE;
  246.     DontPassSelectorType            = FALSE;
  247.     UseNativeISAType                = TRUE;
  248.     FragmentNeedsPreparingType        = FALSE;
  249.     ProcDescriptorIsRelativeType    = TRUE;
  250.     ProcDescriptorType                = (BeginningOf68KCode-Top) / 8;
  251.     Reserved4Type;
  252.     SelectorType                    = 0;
  253.  
  254.     /* PowerPC Routine Record 1 */
  255.     ProcInfoType;
  256.     Reserved3Type;
  257.     ISAType    = kPowerPCISA;
  258.     fill bit [11];
  259.     RoutineIsDispatchedDefaultType     = FALSE;
  260.     DontPassSelectorType             = FALSE;
  261.     UseNativeISAType                 = TRUE;
  262.     FragmentNeedsPreparingType        = TRUE;
  263.     ProcDescriptorIsRelativeType    = TRUE;
  264.     ProcDescriptorType                 = (BeginningOfPowerPCCode-Top) / 8;
  265.     Reserved4Type;
  266.     SelectorType                     = 0;
  267.     Align LONG;
  268.  
  269. BeginningOf68KCode:
  270.     hex string;        // The 68k code starts here
  271.  
  272.     Align LONG;
  273.  
  274. BeginningOfPowerPCCode:
  275.     hex string;        // The PEF container starts here
  276. };
  277.  
  278.